package com.jdk8;

import java.util.Optional;

public class JDK8Optional {

    public static void main(String[] args) {
        Optional<String> o = Optional.of("abc");
        String str = o.get();
        System.out.println(str);

        /*Optional<String> o2 = Optional.of(null);
        String str2 = o2.get();
        System.out.println(str2);*/

        /*Optional<String> o3 = Optional.empty();
        String str3 = o3.get();
        System.out.println(str3);*/

        Optional<String> o4 = Optional.ofNullable("aaa"); //允许为空
        String str4 = o4.orElse("sunjob");//如果为空，则默认为sunjob
        System.out.println(str4);
    }
}
